using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Runtime.InteropServices;
namespace BMC.ARSystem
{
	[ComVisible(false), Guid("4d573f31-33f4-44f7-9f11-380691357080")]
	public abstract class ServerInformation
	{
		internal static ArrayList m_supportedTags;
		private IDictionary m_snapshotData;
		private IDictionary m_modifiedData;
		private Server m_server;
		private DateTime m_snapshotTime;
		private DesignerVerbCollection Verbs
		{
			get
			{
				DesignerVerbCollection designerVerbCollection = new DesignerVerbCollection();
				designerVerbCollection.Add(new DesignerVerb("&Save", new EventHandler(this.OnSave)));
				designerVerbCollection.Add(new DesignerVerb("&Refresh", new EventHandler(this.OnRefresh)));
				return designerVerbCollection;
			}
		}
		public IDictionary Snapshot
		{
			get
			{
				return this.m_snapshotData;
			}
		}
		public static int[] SupportedTags
		{
			get
			{
				object[] array = ServerInformation.m_supportedTags.ToArray();
				int[] array2 = new int[array.Length];
				array.CopyTo(array2, 0);
				return array2;
			}
		}
		internal ServerInformation(Server server)
		{
			this.m_server = server;
			this.m_snapshotData = server.GetServerInfo(ServerInformation.SupportedTags);
			this.m_snapshotTime = server.LastOperationTime;
			this.m_modifiedData = new HybridDictionary(this.m_snapshotData.get_Count());
		}
		static ServerInformation()
		{
			ServerInformation.m_supportedTags = new ArrayList(346);
		}
		public static ServerInformation CreateInstance(Server server)
		{
			int[] tags = new int[]
			{
				4
			};
			IDictionary serverInfo = server.GetServerInfo(tags);
			string text = serverInfo.get_Item(4).ToString();
			string[] array = text.Split(new char[]
			{
				'.'
			});
			if (array.Length > 0)
			{
				int num = int.Parse(array[0]);
				int num2 = (array.Length > 1) ? int.Parse(array[1]) : 0;
				if (num > 7 || (num >= 7 && num2 >= 1))
				{
					return new ServerInformation71(server);
				}
				if (num >= 6 && num2 >= 3)
				{
					return new ServerInformation63(server);
				}
				if (num >= 5 && num2 >= 1)
				{
					return new ServerInformation51(server);
				}
				if (num >= 4 && num2 >= 5)
				{
					return new ServerInformation45(server);
				}
				if (num >= 3 && num2 >= 2)
				{
					return new ServerInformation32(server);
				}
			}
			throw new ARException("Unsupported AR Server version! Can not retrieve server information.");
		}
		private void OnSave(object sender, EventArgs e)
		{
			this.m_server.SetServerInfo(this.m_modifiedData);
		}
		private void OnRefresh(object sender, EventArgs e)
		{
			this.m_snapshotData = this.m_server.GetServerInfo(ServerInformation.SupportedTags);
			this.m_snapshotTime = this.m_server.LastOperationTime;
			this.m_modifiedData = new HybridDictionary(this.m_snapshotData.get_Count());
		}
		public void Save()
		{
			this.m_server.SetServerInfo(this.m_modifiedData);
		}
		internal object GetValue(int tag)
		{
			if (this.m_modifiedData.Contains(tag))
			{
				return this.m_modifiedData.get_Item(tag);
			}
			if (this.m_snapshotData.Contains(tag))
			{
				return this.m_snapshotData.get_Item(tag);
			}
			return null;
		}
		internal string GetstringValue(int tag)
		{
			return this.GetValue(tag).ToString();
		}
		internal int GetSqlIntValue(int tag)
		{
			object value = this.GetValue(tag);
			try
			{
				if (value != null && value != DBNull.Value)
				{
					return (int)value;
				}
			}
			catch (Exception var_2_21)
			{
			}
			return -2147483648;
		}
		internal bool GetBoolValue(int tag)
		{
			int sqlIntValue = this.GetSqlIntValue(tag);
			return sqlIntValue == 1;
		}
		internal void SetBoolValue(int tag, bool val)
		{
			this.SetValue(tag, val ? 1 : 0);
		}
		internal void SetValue(int tag, object val)
		{
			if (val != this.m_snapshotData.get_Item(tag))
			{
				this.m_modifiedData.set_Item(tag, val);
			}
		}
		internal static void AddTags(int[] tags)
		{
			for (int i = 0; i < tags.Length; i++)
			{
				int num = tags[i];
				if (!ServerInformation.m_supportedTags.Contains(num))
				{
					ServerInformation.m_supportedTags.Add(num);
				}
			}
		}
		internal static void RemoveTags(int[] tags)
		{
			for (int i = 0; i < tags.Length; i++)
			{
				int num = tags[i];
				ServerInformation.m_supportedTags.Remove(num);
			}
		}
		internal void FetchLazyData(int[] tags)
		{
			if (tags == null || tags.Length <= 0)
			{
				return;
			}
			IDictionary serverInfo = this.m_server.GetServerInfo(tags);
			int i = 0;
			int num = tags.Length;
			while (i < num)
			{
				this.m_snapshotData.set_Item(i, serverInfo.get_Item(i));
				i++;
			}
		}
	}
}
